/*
 * The Open Source Unix Installer
 *
 * The MIT License
 *
 * Copyright 2011-2012 Andrey Pudov.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

/*
 * @author  Andrey Pudov    <andrey@andreypudov.com>
 * @version 0.00.00
 * @name    u_properties.h
 * @date:   Jan 29, 2012
 */

#ifndef INSTALLER_UTIL_U_PROPERTIES_H_
#define INSTALLER_UTIL_U_PROPERTIES_H_

#include <stdio.h>
#include <stdbool.h>

#include "properties.h"

#ifdef __cplusplus
extern "C" {
#endif

bool u_installer_properties_start();                 /* unit entry point */

bool u_installer_properties_new();
bool u_installer_properties_delete();
bool u_installer_properties_get();
bool u_installer_properties_set();

bool u_installer_properties_start() {
    return (u_installer_properties_new()
        && u_installer_properties_delete()
        && u_installer_properties_get()
        && u_installer_properties_set());
}

bool u_installer_properties_new() {
    Properties *properties = installer_properties_new();

    if (properties == NULL) {    
        u_installer_main_print("properties", "new()", true);

        /* deallocation is not necessary */

        return true;
    }
    
    return false;
}

bool u_installer_properties_delete() {
    Properties *properties = installer_properties_new();

    installer_properties_set(&properties, "Key1", "Value1");
    installer_properties_delete(properties);

    u_installer_main_print("properties", "delete()", true);

    return true;
}

bool u_installer_properties_get() {
    Properties *properties = installer_properties_new();

    installer_properties_set(&properties, "Key1", "Value1");
    installer_properties_set(&properties, "Key2", "Value2");
    installer_properties_set(&properties,  NULL, "Value3");
    installer_properties_set(&properties, "Key4", NULL);
    installer_properties_set(&properties, "Key5", "Value5");

    if ((strcmp(installer_properties_get(properties, "Key1"), "Value1") == 0) 
            && (strcmp(installer_properties_get(properties, "Key2"), 
                       "Value2") == 0)
            && (installer_properties_get(properties, "Key4") == NULL)
            && (strcmp(installer_properties_get(properties, "Key5"), 
                       "Value5") == 0)
            && (installer_properties_get(properties, "KeyUnreached") == NULL)) {
        u_installer_main_print("properties", "get()", true);
        installer_properties_delete(properties);

        return true;
    }
    
    installer_properties_delete(properties);
    u_installer_main_print("properties", "get()", false);
    
    return false;
}

bool u_installer_properties_set() {
    /* unit case is a part of get */
    u_installer_main_print("properties", "set()", true);

    return true;
}

#ifdef __cplusplus
}
#endif

#endif /* INSTALLER_UTIL_U_PROPERTIES_H_ */ 
